Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 fix TestClusterExtensionInstallReResolvesWhenNewCataloge2e test #1008

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yashoza19
Copy link
Contributor

@yashoza19 yashoza19 commented Jul 2, 2024

Description

  • Created a new Catalog v2 with Prometheus bundle 2.0.0
  • Changes made to build-push-e2e-catalog.sh to allow building and pushing new catalog image
  • Changes made to TestClusterExtensionInstallReResolvesWhenNewCatalog e2e test -
  1. Install ClusterExtension with existing Catalog(v1) which has Prometheus v1.2.0
  2. Once Prometheus v1.2.0 is installed, patch the ExtensionCatalog with the newly created catalog v2
  3. Wait and confirm that ClusterExtension picks the prometheus v2.2.0 from test-catalog:v2 and resolves to a successful install

fixes #945

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@yashoza19 yashoza19 requested a review from a team as a code owner July 2, 2024 15:52
Copy link

netlify bot commented Jul 2, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 20194e8
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/6691a490fff7c50009931dec
😎 Deploy Preview https://deploy-preview-1008--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.46%. Comparing base (60d26ed) to head (20194e8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1008   +/-   ##
=======================================
  Coverage   73.46%   73.46%           
=======================================
  Files          32       32           
  Lines        1986     1986           
=======================================
  Hits         1459     1459           
  Misses        368      368           
  Partials      159      159           
Flag Coverage Δ
e2e 55.89% <ø> (+0.05%) ⬆️
unit 45.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yashoza19 yashoza19 force-pushed the issue945 branch 2 times, most recently from 09ff7f3 to 4065eb1 Compare July 2, 2024 22:45
Comment on lines 63 to 81
func patchTestCatalog(ctx context.Context, name string, newImageRef string) (*catalogd.ClusterCatalog, error) {
// Fetch the existing ClusterCatalog
catalog := &catalogd.ClusterCatalog{}
err := c.Get(ctx, client.ObjectKey{Name: name}, catalog)
if err != nil {
return nil, err
}

// Update the ImageRef
catalog.Spec.Source.Image.Ref = newImageRef

// Patch the ClusterCatalog
err = c.Update(ctx, catalog)
if err != nil {
return nil, err
}

return catalog, err
}
Copy link
Member

@joelanford joelanford Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a valid test case (where we patch the spec of a ClusterCatalog), but it does not cover the case I had in mind (and a case I think we need to cover).

What I have in mind here specifically is that we need to prove that the polling behavior alone is enough to trigger an upgrade of a ClusterExtension. Forcing a change by changing the image in the ClusterCatalog spec is a side-effect foils the true intention of the test.

This "polling triggers an upgrade" test is one of the most important features of OLM, so we unfortunately can't "fake" it by touching the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first approach as well. Unfortunately, I can't find a way to change the latest image tag on a local registry. crane does not allow to change tags on local registries, hence I took this approach. Let me know if you you think this is still a valid test or we can approach this issue with a different solution. @joelanford

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "polling triggers an upgrade" test is one of the most important features of OLM, so we unfortunately can't "fake" it my touching the spec.

How is this accomplished in the current version of OLM? The use of make/sh/kinako(spelling), to get things into the cluster, the go to run tests, IMO blurs what is/isn't being tested, there aren't clear separation of duties in this model.

Correct me if I'm wrong, but I think you want an image loaded into the running cluster after the test has executed? Is that correct? Or do you just want this test to run longer to see if the polling picks up the the image already in the registry?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this accomplished in the current version of OLM?

I'm not sure

The use of make/sh/kinako(spelling), to get things into the cluster, the go to run tests, IMO blurs what is/isn't being tested, there aren't clear separation of duties in this model.

I agree that the number of moving parts is a problem. I'm fairly confident that if we wanted something a bit leaner, we could build all of this in Go.

  1. Code in go that runs during an e2e that deploys an image registry in the cluster.
  2. Client-go code that runs kubectl port-forward to give the e2e test a way to communicate with the registry.
  3. go-containerregistry code to push images, move tags, etc.

Correct me if I'm wrong, but I think you want an image loaded into the running cluster after the test has executed? Is that correct?

No, I don't think that is sufficient because the polling behavior of catalogd queries a remote registry. kind load would not make it visible to the polling process. What I'm after is $something that causes the digest of a tag to change mid way through the test. That could be one of:

  1. Pre-populating the registry with two catalog images as part of the setup, and then during the test re-tagging the second image over the first.
  2. Pushing the first image at repo:tag as part of the setup, and then pushing the second image at that same repo:tag during the test.

@yashoza19 yashoza19 force-pushed the issue945 branch 3 times, most recently from 8df658c to 15642b7 Compare July 9, 2024 02:16
// Tag the image with the new tag
baseImage := "localhost:30000/e2e/test-catalog:v1"
var err error
err = crane.Tag(baseImage, "latest", crane.Insecure)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "latest" be parsed from the value of testLatestCatalogRefEnvVar (instead of being hardcoded)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testLatestCatalogRefEnvVar consist of the complete image path with latest tag. We just need to tag name and not the complete image name here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but if we change that environment variable value to use a different tag, we'd have to change all the hardcoded "latest" references in the e2e code as well. If we parse the tag out of the reference, there's just the one source of truth (but also see my other comment about possibly refactoring the envvars).

t.Log("It resolves again when a new catalog is available")

// Tag the image with the new tag
baseImage := "localhost:30000/e2e/test-catalog:v1"
Copy link
Member

@joelanford joelanford Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just me or does it feel like there was some envvar sprawl before this PR, and this PR is making it more apparent with the addition of the second catalog image?

It somewhat feels like we should either:

  1. Completely get rid of the envvars and just hardcode the references in the e2e test code
  2. Take a more holistic look at the envvars used to carry image reference and take an opportunity to refactor/reduce
    • For example, should we have LOCAL_REGISTRY_HOST and CLUSTER_REGISTRY_HOST, and then every single repo/image/tag we'd use would get its own envvar with a consistent naming convention?

}, pollDuration, pollInterval)

// update tag on test-catalog image with v2 image
t.Log("By creating an ClusterExtension catalog with the updated ClusterCatalog")
Copy link
Member

@joelanford joelanford Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message seems incorrecT?

Suggested change
t.Log("By creating an ClusterExtension catalog with the updated ClusterCatalog")
t.Log("By updating the catalog tag to point to the v2 catalog")

@yashoza19 yashoza19 force-pushed the issue945 branch 3 times, most recently from 75b2968 to 8ea854c Compare July 9, 2024 04:22
@yashoza19 yashoza19 requested a review from joelanford July 9, 2024 04:33
Comment on lines +127 to +128
export LOCAL_REGISTRY_HOST := $(E2E_REGISTRY_NAME).$(E2E_REGISTRY_NAMESPACE).svc:5000
export CLUSTER_REGISTRY_HOST := localhost:30000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what others think, but to me it is more logical to flip these. LOCAL for localhost, CLUSTER for the service-based name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't call localhost a host, this is the ENDPOINT into the the cluster. It's really the external callable address. Spitballing, because names are hard, but maybe CLUSTER_REGISTRY_INGRESS?

I agree the svc:5000 address should be called CLUSTER.

Makefile Outdated
Comment on lines 129 to 136
export V1_IMAGE_TAG := v1
export V2_IMAGE_TAG := v2
export LATEST_IMAGE_TAG := latest
export CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/e2e/test-catalog:$(V1_IMAGE_TAG)
export UPDATED_CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/e2e/test-catalog:$(V2_IMAGE_TAG)
export LATEST_CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/e2e/test-catalog:$(LATEST_IMAGE_TAG)
export CLUSTER_V1_CATALOG_IMG := $(CLUSTER_REGISTRY_HOST)/e2e/test-catalog:$(V1_IMAGE_TAG)
export CLUSTER_V2_CATALOG_IMG := $(CLUSTER_REGISTRY_HOST)/e2e/test-catalog:$(V2_IMAGE_TAG)
Copy link
Member

@joelanford joelanford Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments here:

  1. I don't think we need envvars for every combo. Let's just concatenate.
  2. Let's pick a convention like <repoName>_<imageName_<tag> and use that.
  3. I don't think we'll need a "latest" variant here anymore. The test that needs it can deal with pushing its own tag local to the test.

So I think all of this can boil down to:

Suggested change
export V1_IMAGE_TAG := v1
export V2_IMAGE_TAG := v2
export LATEST_IMAGE_TAG := latest
export CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/e2e/test-catalog:$(V1_IMAGE_TAG)
export UPDATED_CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/e2e/test-catalog:$(V2_IMAGE_TAG)
export LATEST_CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/e2e/test-catalog:$(LATEST_IMAGE_TAG)
export CLUSTER_V1_CATALOG_IMG := $(CLUSTER_REGISTRY_HOST)/e2e/test-catalog:$(V1_IMAGE_TAG)
export CLUSTER_V2_CATALOG_IMG := $(CLUSTER_REGISTRY_HOST)/e2e/test-catalog:$(V2_IMAGE_TAG)
export E2E_TESTCATALOG_V1 := e2e/testcatalog:v1
export E2E_TESTCATALOG_V2 := e2e/testcatalog:v2

And then when we need to reference a fully-qualified image, we would just use, for example:

$(LOCAL_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we still need to export the cluster image as CLUSTER_V1_CATALOG_IMG := $(CLUSTER_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V1) in the makefile, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong @joelanford, but I think you want less stuff in the Makefile, and more of the work in the tests that need "additional" things. IE instead of exported vars, concatenate them in the go code? So it would be something like:

fmt.Sprintf("%s/%s", os.Getenv("LOCAL_REGISTRY_HOST"), os.Getenv("E2E_TEST_CATALOG_V1"))

Or did you mean something entirely different.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What @acornett21 said. I think there may be at least one place in the Makefile where we have to build/push the image, and that needs the fully-qualifed image reference.

In that case, I'd concatenate them just right at the call site rather than making an extra variable to store the concatenation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been implemented now in the latest commit. Thanks

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2024
@yashoza19 yashoza19 force-pushed the issue945 branch 2 times, most recently from b805ce9 to a9f83ce Compare July 9, 2024 17:13
export CLUSTER_REGISTRY_HOST := localhost:30000
export E2E_TEST_CATALOG_V1 := e2e/test-catalog:v1
export E2E_TEST_CATALOG_V2 := e2e/test-catalog:v2
export CATALOG_IMG := $(LOCAL_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need CATALOG_IMG variable anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -24,6 +25,7 @@ var (
const (
testCatalogRefEnvVar = "CATALOG_IMG"
testCatalogName = "test-catalog"
LatestImageTag = "latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to export this? I'd suggest unexporting:

Suggested change
LatestImageTag = "latest"
latestImageTag = "latest"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll hit this in a quick follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the changes in this PR itself

Signed-off-by: yashoza19 <yoza@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix: e2e test for re-reconcile on catalog change is not valid
4 participants